from core.basehandler import BaseHandler
from core.room import Room
from core.support import set_cutscene, get_game
from core.action import Action

class bush1(Room):
    def __init__(self, room_id):
        Room.__init__(self, room_id)    # do basic initialization for every room
        self.hyena_alive = True
           
        # build list of actions
        self.add_action(Out)
        self.add_action(Down)
        self.add_action(Hunt)
    
    # return description of room.
    def get_description(self):
        if self.hyena_alive:
            return 'You cut through the bush, and eventually come across a leopard eating a corpse.  You can either try to kill it with your knife, or run back to the lodge.'
        else:
            return 'You see the corpse of your friend Scott and the leopard.'
        
    # return image of room
    def get_image(self):
        if self.hyena_alive:
            return 'leopard.jpg'
        else:
            return 'scott.jpg'
    
    def gun_has_bullets(self):
        game = get_game()
        player = game.get_player()
        if 'gun' in player.inventory:
            #if player.inventory['gun'].bullets:
            if player.inventory['gun'].bullets >0:
                return True
            else: 
                return False

class Bush1Handler(BaseHandler):
    
    # return class to use to create a new instance of this room
    def get_room_class(self):
        return bush1

# define actions for this room

class Out(Action):
    def __init__(self):
        Action.__init__(self, "Out")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Walk back toward the lodge"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        
        return 'outside'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"


class Down(Action):
    def __init__(self):
        Action.__init__(self, "Down")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Continue through the bush"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        game = get_game()
        if 'lion' in game.rooms:
            return 'bush3'
        elif self.room.hyena_alive:
            return 'bush1'
        else:
            return 'lion'
            
    def do_action(self,game,room,request):
        if self.room.hyena_alive:
            set_cutscene("The leopard growls angry as you try to pass it.  You decide to step back")
        return


    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"

class Hunt(Action):
    def __init__(self):
        Action.__init__(self, "Hunt")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Hunt"
    
    def is_enabled(self):
        if self.room.gun_has_bullets():
            return True
        else:
            return False
        
    # return id of room to enter when action is complete
    def get_destination(self):
        return 'hunt'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"
    